package com.situ.day11;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.Scanner;

import org.junit.Test;

public class Str {
	@Test
	public void test1() {
		String str1 = "Hello World";
		String str2 = str1.toLowerCase();
		System.out.println(str2);
		String str3 = str1.toUpperCase();
		System.out.println(str3);
		char ch = str1.charAt(1);
		System.out.println(ch);
		char[] charArray = str1.toCharArray();
		for (int i = 0; i < charArray.length; i++) {
			if (charArray[i] >= 'A' && charArray[i] <= 'Z') {
				charArray[i] = (char) (charArray[i] + 32);
			}
			System.out.println(charArray[i]);
		}
	}

	@Test
	public void test2() {
		String str = "Hello World";
		String str1 = str.toLowerCase();
		System.out.println(str1);
		String str2 = str.toUpperCase();
		System.out.println(str2);
		char ch = str.charAt(2);
		System.out.println(ch);
		char[] charArray = str.toCharArray();
		for (int i = 0; i < charArray.length; i++) {
			if (charArray[i] >= 'A' && charArray[i] <= 'Z') {
				charArray[i] = (char) (charArray[i] + 32);
			}
			System.out.println(charArray[i]);
		}
	}

	@Test
	public void test3() {
		String str = "Ni Hao Ma";
		String str1 = str.toLowerCase();
		System.out.println(str1);
		String str2 = str.toUpperCase();
		System.out.println(str2);
		char ch = str.charAt(0);
		System.out.println(ch);
		char[] charArray = str.toCharArray();
		for (int i = 0; i < charArray.length; i++) {
			if (charArray[i] >= 'A' && charArray[i] <= 'Z') {
				charArray[i] = (char) (charArray[i] + 32);
			}
			System.out.println(charArray[i]);
		}
	}

	@Test
	public void test4() {
		String str = "Hello World";
		String str1 = str.toLowerCase();
		System.out.println(str1);
		String str2 = str.toUpperCase();
		System.out.println(str2);
		char ch = str.charAt(5);
		System.out.println(ch);
		char[] charArray = str.toCharArray();
		for (int i = 0; i < charArray.length; i++) {
			if (charArray[i] >= 'A' && charArray[i] <= 'Z') {
				charArray[i] = (char) (charArray[i] + 32);
			}
			System.out.println(charArray[i]);
		}
	}

	@Test
	public void test5() {
		Scanner scanner = new Scanner(System.in);
		System.out.println("请输入学生成绩");
		int score = scanner.nextInt();
		if (score > 100 || score < 0) {
			System.out.println("输入的数字不正确");
			return;
		}
		if (score >= 90 && score < 100) {
			System.out.println("优秀");
		} else if (score >= 80 && score < 90) {
			System.out.println("良好");
		} else if (score >= 70 && score < 80) {
			System.out.println("一般");
		} else if (score >= 60 && score < 70) {
			System.out.println("及格");
		} else {
			System.out.println("不及格");
		}
	}

	@Test
	public void test6() {
		for (int i = 0; i < 5; i++) {
			for (int j = 0; j <= i; j++) {
				System.out.print("*");
			}
			System.out.println();
		}
	}

	@Test
	public void test7() {
		try {
			FileInputStream fileInputStream = new FileInputStream("a.txt");
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		}
	}

	@Test
	public void test8() {
		int num1 = 3;
		int num2 = 1;
		System.out.println("------start------");
		try {
			int num3 = num1 / num2;
			System.out.println(num3);
		} catch (ArithmeticException e) {
			System.out.println("catch ArithmeticException");
			e.printStackTrace();
		} finally {
			System.out.println("------finally--------");
		}
		System.out.println("------end-------");
	}

	@Test
	public void test9() {
		int num1 = 5;
		int num2 = 1;
		try {
			int num3 = num1 / num2;
			System.out.println(num3);
		} catch (ArithmeticException e) {
			e.printStackTrace();
		}
	}

	@Test
	public void test10() {
		try {
			FileInputStream fileInputStream = new FileInputStream("a.txt");
		} catch (FileNotFoundException e) {
			System.out.println("catch FileNotFoundException");
			e.printStackTrace();
		}
	}

	@Test
	public void test11() {
		int num1 = 2;
		int num2 = 0;
		try {
			int num3 = num1 / num2;
			System.out.println("-----start-----");
		} catch (ArithmeticException e) {
			System.out.println("catch ArithmeticException");
			e.printStackTrace();
		} finally {
			System.out.println("-------finally-------");
		}
		System.out.println("--------end--------");
	}

	@Test
	public void test12() {
		int num1 = 3;
		int num2 = 1;
		System.out.println("----start------");
		try {
			int result = num1 / num2;
			int[] array = new int[2];
			array[2] = 3;
		} catch (ArithmeticException e) {
			System.out.println("catch ArithmeticException");
			e.printStackTrace();
		} catch (ArrayIndexOutOfBoundsException e) {
			System.out.println("catch ArrayIndexOutOfBoundsException");
			e.printStackTrace();
		} catch (Exception e) {
			System.out.println("catch Exception");
			e.printStackTrace();
		} finally {
			System.out.println("------finally-------");
		}
		System.out.println("------end------");
	}

}
